//
//  PopoverBootcamp.swift
//  FCSwiftUI
//
//  Created by 冯宣超 on 2023/2/24.
//

import SwiftUI

struct PopoverBootcamp: View {
    
    @State var showNewScreeen: Bool = false
    
    var body: some View {
        ZStack {
            Color.orange.edgesIgnoringSafeArea(.all)
            
            VStack {
                Button("BUTTON") {
                    showNewScreeen.toggle()
                }
                .font(.largeTitle)
                
                Spacer()
            }
            // Method 1 - SHEET
//            .sheet(isPresented: $showNewScreeen) {
//                NewScreen()
//            }
            
            // Method 2 - TRANSITION
//            ZStack {
//                if (showNewScreeen) {
//                    NewScreen(showNewScreeen: $showNewScreeen)
//                        .padding(.top, 100)
//                        .transition(AnyTransition.move(edge: .bottom))
//                        .animation(.spring())
//                }
//            }
//            .zIndex(2.0)
            
            // Method 3 - ANIMATION OFFSET
            NewScreen(showNewScreeen: $showNewScreeen)
                .padding(.top, 100)
                .offset(y: showNewScreeen ? 0 : UIScreen.main.bounds.height)
                .animation(.spring())
            
        }
        
    }
}

struct NewScreen: View {
    
    @Environment(\.dismiss) var dismiss
    @Binding var showNewScreeen: Bool
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            Color.purple.edgesIgnoringSafeArea(.all)
            
            Button {
                showNewScreeen.toggle()
                dismiss()
            } label: {
                Image(systemName: "xmark")
            }
            .foregroundColor(.white)
            .font(.largeTitle)
            .padding(20)
        }
    }
    
}

struct PopoverBootcamp_Previews: PreviewProvider {
    static var previews: some View {
        PopoverBootcamp()
    }
}
